package 第二次实验.第四个实验;

import chapter10.jsjf.LinkedBinaryTree;
import chapter10.课本代码.表达式树.PostfixEvaluator;

import java.util.Iterator;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
//        infixtree a =new infixtree();
//        a.maketree("1+2+(1+2)");
        int result;
        Scanner in = new Scanner(System.in);
        infixtree a = new infixtree();
        LinkedBinaryTree b =new LinkedBinaryTree();
      //  b.root=a.maketree("1 + 2 * ( 2 + 9 )");
        String pre = in.nextLine();
        b.root=a.maketree(pre);
        System.out.println(b.toString());
        String result1="";

        Iterator pp = b.iteratorPostOrder();
        while (pp.hasNext()){
            result1+=pp.next()+" ";
        }

        System.out.println(result1);

        PostfixEvaluator evaluator = new PostfixEvaluator();
            result = evaluator.evaluate(result1);
            System.out.println();
            System.out.println("That expression equals " + result);



    }
}
